package com.haust.dianqi.service.impl;

import com.haust.dianqi.mapper.ArticleMapper;
import com.haust.dianqi.pojo.Article;
import com.haust.dianqi.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Auther: csp1999
 * @Date: 2020/10/10/16:19
 * @Description: 文章service接口实现类
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public Article addArticle(Article article) {

        String id = UUID.randomUUID().toString();

        article.setId(id);
        article.setDate(new Date());
        article.setViews(0);
        articleMapper.addArticle(article);

        return article;
    }

    @Override
    public Article queryArticleById(String id) {
        return articleMapper.queryArticleById(id);
    }

    @Override
    public List<Article> getArticleByType(Integer type) {
        return articleMapper.queryArticlesByType(type);
    }

    @Override
    public List<Article> queryCurrentPublic() {
        Integer type = 2;
        return articleMapper.queryCurrentIndexInfo(type);
    }

    @Override
    public List<Article> queryCurrentNews() {
        Integer type = 1;
        return articleMapper.queryCurrentIndexInfo(type);
    }

}
